package com.example.broad;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.example.broad.receiver.StandardReceiver;

/**
  *
  * @description 标准广播
  * @param 
  * @return 
  * author snjgm
  * time 2022/7/22 下午5:30
  */
public class BroadStandardActivity extends AppCompatActivity implements View.OnClickListener {

    private StandardReceiver standardReceiver;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad_standard);
        findViewById(R.id.btn_sendBroad).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_sendBroad:
                Intent intent = new Intent(StandardReceiver.STANDARD_ACTION);
                sendBroadcast(intent);
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        standardReceiver = new StandardReceiver();
        //创建一个意图过滤器,只处理STANDARD_ACTION的广播
        IntentFilter filter = new IntentFilter(StandardReceiver.STANDARD_ACTION);
        //注册接收器，注册之后才能正常接收广播
        registerReceiver(standardReceiver , filter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(standardReceiver);
    }
}